package com.bestom.videoplay.callback;

import android.content.Intent;
import android.media.MediaPlayer;
import android.net.Uri;
import android.util.Log;
import android.view.SurfaceHolder;

import androidx.annotation.NonNull;

import com.bestom.videoplay.MediaApplication;
import com.bestom.videoplay.R;

import java.io.IOException;

public class SurfaceCallback implements SurfaceHolder.Callback {

    private MediaPlayer mediaPlayer = MediaApplication.getApplication().getMediaPlayer();

    @Override
    public void surfaceCreated(@NonNull SurfaceHolder surfaceHolder) {
        mediaPlayer.setDisplay(surfaceHolder);
        try {
//            mediaPlayer.prepareAsync();
        }catch (IllegalStateException e){}

        mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
            @Override
            public void onCompletion(MediaPlayer mediaPlayer) {
//                mediaPlayer.seekTo(0);

            }
        });
    }

    @Override
    public void surfaceChanged(@NonNull SurfaceHolder surfaceHolder, int i, int i1, int i2) {

    }

    @Override
    public void surfaceDestroyed(@NonNull SurfaceHolder surfaceHolder) {

    }
}
